﻿
using System.Collections.Generic;
using System.IO;
namespace sharpxbot.Utils.IO
{
    public class FileUtil
    {
        /// <summary>
        /// Gets all files matching given extension from given directory recursively
        /// </summary>
        /// <param name="path">Initial lookup path</param>
        /// <param name="fileExtension">File extension</param>
        /// <returns></returns>
        public IEnumerable<FileInfo> GetFiles(string path, string fileExtension)
        {
            List<FileInfo> result = new List<FileInfo>();

            try
            {
                DirectoryInfo dir = new DirectoryInfo(path);
                if (dir.Exists)
                {
                    result.AddRange(dir.EnumerateFiles(fileExtension, SearchOption.AllDirectories));
                }
            }
            catch { }

            return result;
        }
    }
}
